#!/bin/bash
zoomCard=`aplay -l | grep "ZOOM G Series" | cut -d':' -f 1| cut -d' ' -f2`
#systemCard=`aplay -l | grep "ALC887-VD Digital" | cut -d':' -f 1| cut -d' ' -f2`
systemCard=`aplay -l | grep "FastTrack" | head -n 1 - | cut -d':' -f 1| cut -d' ' -f2`
#/usr/bin/jackd -R -P 94 -T -d alsa -n 3 -r 44100 -C hw:${zoomCard},0 -P hw:${systemCard},0 -S --period 256 &


/usr/bin/jackd -R -P 94 -T -d alsa -n 3 -r 44100 -C hw:${systemCard},1 -P hw:${systemCard},0 -S --period 256  &

sleep 2
qsynth &
hydrogen &
yoshimi -S  &
non-mixer --osc-port=7587 non-mixer-pro/test/ &

mididings -f skeleton.py &

ttymidi -b 9600 -v -s /dev/ttyACM0 &

##qarecord --jack --channels 8 &

sleep 10

a2jmidid -ue &

slgui -t 66 -L slgui.session.4.slsess -m snooper-looper-midi-bindings.slb &

### pactl load-module module-jack-sink channels=2; pactl load-module module-jack-source channels=2;pacmd set-default-sink jack_out

sleep 5
jack_connect system:capture_1 "Non-Mixer/git:in-1" 
jack_connect system:capture_2 "Non-Mixer/git:in-2" 
jack_connect system:capture_2 "Non-Mixer/git:in-1"
jack_connect system:capture_1 "Non-Mixer/git:in-2"
jack_connect Non-Mixer/git:out-1 "sooperlooper:common_in_1" 
jack_connect Non-Mixer/git:out-2 "sooperlooper:common_in_2" 
jack_connect Non-Mixer/git:out-1 "Non-Mixer/all:in-1" 
jack_connect Non-Mixer/git:out-2 "Non-Mixer/all:in-2" 

sleep 1
jack_connect qsynth:l_00 Non-Mixer/keys:in-1
jack_connect qsynth:r_00 Non-Mixer/keys:in-2

jack_connect yoshimi:left Non-Mixer/keys:in-1
jack_connect yoshimi:right Non-Mixer/keys:in-2

sleep 1
jack_connect Non-Mixer/keys:out-1 sooperlooper:common_in_1
jack_connect Non-Mixer/keys:out-2 sooperlooper:common_in_2
jack_connect Non-Mixer/keys:out-1 Non-Mixer/all:in-1
jack_connect Non-Mixer/keys:out-2 Non-Mixer/all:in-2


jack_connect Hydrogen:out_L Non-Mixer/drum:in-1 
jack_connect Hydrogen:out_R Non-Mixer/drum:in-2 

sleep 1
jack_connect Non-Mixer/drum:out-1 sooperlooper:common_in_1
jack_connect Non-Mixer/drum:out-2 sooperlooper:common_in_2
jack_connect Non-Mixer/drum:out-1 Non-Mixer/all:in-1
jack_connect Non-Mixer/drum:out-2 Non-Mixer/all:in-2




sleep 1

# Pętla na wyjście 
#jack_connect sooperlooper:common_out_1 system:playback_1
#jack_connect sooperlooper:common_out_2 system:playback_2
jack_connect sooperlooper:common_out_1 Non-Mixer/all:in-1
jack_connect sooperlooper:common_out_2 Non-Mixer/all:in-2




sleep 1
jack_connect "Non-Mixer/git:out-1" qarecord:in_0 
jack_connect "Non-Mixer/git:out-2" qarecord:in_1 
jack_connect Non-Mixer/keys:out-1 qarecord:in_2
jack_connect Non-Mixer/keys:out-2 qarecord:in_3

sleep 1
jack_connect Non-Mixer/drum:out-1 qarecord:in_4
jack_connect Non-Mixer/drum:out-2 qarecord:in_5
jack_connect sooperlooper:common_out_1 qarecord:in_6
jack_connect sooperlooper:common_out_2 qarecord:in_7


sleep 1

jack_connect "a2j:ttymidi (capture): MIDI out" "a2j:mididings (playback): in_1" 
jack_connect "a2j:ttymidi (capture): MIDI out" "a2j:sooperlooper (playback): sooperlooper" 
jack_connect "a2j:ttymidi (capture): MIDI out" "a2j:Hydrogen (playback): Hydrogen Midi-In"

jack_connect "a2j:mididings (capture): fluidsynth" "`jack_lsp | grep -Poe "a2j:FLUID Synth .*"`"
jack_connect "a2j:mididings (capture): sooperlooper" "a2j:sooperlooper (playback): sooperlooper"
jack_connect "a2j:mididings (capture): hydrogen" "a2j:Hydrogen (playback): Hydrogen Midi-In"
jack_connect "a2j:mididings (capture): yoshimi" "yoshimi:midi in"

sleep 1
 
# Sterowanie loopem z sekwencera 
#jack_connect "`jack_lsp | grep -Poe "a2j:harmonySEQ \[.+\] \(capture\)\: harmonySEQ output"`" "`jack_lsp | grep -Poe "a2j:sooperlooper \[.+\] \(playback\)\: sooperlooper"`"
# Sterowanie sekwencera sekwencerem
#jack_connect "`jack_lsp | grep -Poe "a2j:harmonySEQ \[.+\] \(capture\)\: harmonySEQ output"`" "`jack_lsp | grep -Poe "a2j:harmonySEQ \[.+\] \(playback\)\: harmonySEQ input"`"

########## MIDI
##aconnect harmonySEQ "FLUID Synth (2670)"
###aconnect harmonySEQ "`aconnect -ol | grep -Poe "FLUID Synth.+\)"`"
#aconnect "MPK mini" "Hydrogen"
#aconnect "MPK mini" "sooperlooper"
aconnect "MPK mini" "mididings"
#aconnect "mididings" "FLUID Synth"

#aconnect "MPK mini" qmidiroute
#aconnect "qmidiroute:1" "`aconnect -ol | grep -Poe "FLUID Synth.+\)"`"
#aconnect "qmidiroute:2" "`aconnect -ol | grep -Poe "FLUID Synth.+\)"`"
#aj-snapshot -x -r Muzyka/sesje-jack 
# jack_capture_gui &

jack_disconnect Hydrogen:out_L system:playback_1
jack_disconnect Hydrogen:out_R system:playback_2

jack_disconnect qsynth:l_00 system:playback_1
jack_disconnect qsynth:r_00 system:playback_2


jack_connect Non-Mixer/all:out-1 system:playback_1
jack_connect Non-Mixer/all:out-2 system:playback_2	



patchage 


